/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.msg.hrappy.backend.service.beans;

import edu.msg.hrappy.backend.model.DepartmentType;
import edu.msg.hrappy.backend.repository.DepartmentTypeRepository;
import edu.msg.hrappy.backend.repository.exception.RepositoryException;
import edu.msg.hrappy.backend.service.DepartmentTypeService;
import edu.msg.hrappy.backend.service.exception.ServiceException;
import java.util.Collections;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author toroke
 */
@Stateless
public class DepartmentTypeServiceBean implements DepartmentTypeService{

    @EJB
    private DepartmentTypeRepository departmentTypeDAO;

    @Override
    public void insert(DepartmentType obj) {

        try {
            departmentTypeDAO.insert(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public void update(DepartmentType obj) {
        try {
            departmentTypeDAO.update(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public void delete(DepartmentType obj) {
        try {
            departmentTypeDAO.delete(obj);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }

    }

    @Override
    public List<DepartmentType> getAll() {
        List<DepartmentType> all = Collections.emptyList();
        try {
            all = departmentTypeDAO.getAll();
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }
        return all;
    }

    @Override
    public DepartmentType getById(Long id) {
        DepartmentType one;
        try {
            one = departmentTypeDAO.getById(id);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }
        return one;
    }


    @Override
    public DepartmentType getByName(String name) {
         DepartmentType one;
        try {
            one = departmentTypeDAO.getByName(name);
        } catch (RepositoryException e) {
            throw new ServiceException("", e);
        }
        return one;
    }
    
}
